<?php
/************************FoxPHP威客系统************************/
/*                                                            */
/*  FoxPHP.Com (C)2006-2016 FoxPHP Inc.                       */
/*  This is NOT a freeware, use is subject to license terms   */
/*  FoxPHP威客系统是商业软件,使用于商业用途请购买授权         */
/*  V3.0 2016.3                                               */
/*  foxphp@aliyun.com                                         */
/*  http://www.foxphp.com                                     */
/*                                                            */
/**************************************************************/

namespace Admin\Controller;
use Think\Controller;
class ShopcertificateController extends IndexController {
	
	//列表动作-----------------------------------------------------------------------------------------------
	public function indexAction(){
		
		$model=new \Admin\Model\ShopCertificateModel();

		foreach($model->IndexGetData(
				//排序
				array(
					array('order'=>'id','name'=>'ID'),
					array('order'=>'thumb','name'=>'证件'),
					array('order'=>'uid','name'=>'用户UID'),
					array('order'=>'usertype','name'=>'认证类型'),
					array('order'=>'realname','name'=>'实名'),
					array('order'=>'status','name'=>'申请状态'),
					array('order'=>'content','name'=>'失败原因'),
					array('order'=>'dateline','name'=>'申请时间'),
					array('order'=>'checktime','name'=>'审核时间')
				),
				//查询
				array(	
					'id'=>array('id','int'),
					'uid'=>array('uid','int')
				)
				
			) as $key=>$value){
			$this->assign($key,$value);
		}

		$this->display();
	}
	
	//店铺认证操作-----------------------------------------------------------------------------------------------
	public function operateAction(){
			
		if(!empty($_POST['Success'])){
			
			$ids=GetCheckBox($_POST['checkbox']);
			if(!$ids){
				$ids=intval($_GET['id']);
			}
			if($ids){
				
				M('ShopCertificate')->token(false)->where(" id IN($ids) ")->save(array('status'=>5,'checktime'=>@time()));
				
				$certificatearr=M('ShopCertificate')->token(false)->where(" id IN($ids) ")->select();
				
				if(!empty($certificatearr)){
					$uids='';
					foreach($certificatearr as $certificate){
						if($uids){
							$uids=','.$certificate['uid'];
						}else{
							$uids=$certificate['uid'];
						}
					}
					if($uids){
						M('Member')->token(false)->where(" uid IN($uids) ")->save(array('realname'=>1,'isshop'=>1));
					}
				}
				
				
				$refresh.='<p>'.$ids.'设置审核通过成功！</p>';

			}else{

				$refresh='<p>请选操作数据！</p>';

			}
			
		}elseif(!empty($_POST['Failure'])){
			
			$ids=GetCheckBox($_POST['checkbox']);
			if(!$ids){
				$ids=intval($_GET['id']);
			}
		  
			if($ids){
				
				$content=I('post.content');
				
				M('ShopCertificate')->token(false)->where(" id IN($ids) ")->save(array('status'=>2,'checktime'=>@time(),'content'=>$content));

				$refresh.='<p>'.$ids.'设置审核失败成功！</p>';

			}else{

				$refresh='<p>请选操作数据！</p>';

			}
			
		}else{
			
			$this->deleteAction();
		}
		
		$this->error($refresh,U(MODULE_NAME.'/'.CONTROLLER_NAME.'/index'),3);
		
	}
	
	//审核动作-----------------------------------------------------------------------------------------------
	public function showAction(){
		$id=I('get.id',0,'int');
		$manage=M('ShopCertificate')->token(false)->where(" id=$id ")->find();
		if(!$manage['id']){
			$this->error('修改数据不存在!',U(MODULE_NAME.'/'.CONTROLLER_NAME.'/index'),3);
		}
			
		$this->assign('manage',$manage);
		$this->assign('id',$manage['id']);
		$this->display('Shopcertificate:add');
	}
	
	//删除动作-----------------------------------------------------------------------------------------------
	public function deleteAction(){
		
		$ids=GetCheckBox($_POST['checkbox']);
		  
		if($ids){
			
			$certificatearr=M('ShopCertificate')->token(false)->where(" id IN($ids) ")->select();
			
			if(!empty($certificatearr)){
				$uids='';
				foreach($certificatearr as $certificate){
					if($uids){
						$uids=','.$certificate['uid'];
					}else{
						$uids=$certificate['uid'];
					}
				}
				if($uids){
					M('Member')->token(false)->where(" uid IN($uids) ")->save(array('realname'=>0,'isshop'=>0));
				}
			}
			
			M('ShopCertificate')->token(false)->where(" id IN($ids) ")->delete();

			$refresh.='<p>'.$ids.'认证删除成功！</p>';

		}else{

			$refresh='<p>请选操作数据！</p>';

		}
		
		$this->error($refresh,U(MODULE_NAME.'/'.CONTROLLER_NAME.'/index'),3);
	}
	
}